package com.ld.tool.window;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import org.jetbrains.annotations.NotNull;

import java.util.Date;
import java.util.concurrent.ConcurrentHashMap;

public class TranslateMainWindow implements ToolWindowFactory {

    private static volatile ConcurrentHashMap<Project,TranslatePanel> translatePanelMap = new ConcurrentHashMap<>();


    @Override
    public void init(ToolWindow window) {
    }

    @Override
    public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
        ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
        translatePanelMap.put(project,new TranslatePanel());
        System.out.println("create time"+new Date());
        toolWindow.getContentManager().addContent(contentFactory.createContent(translatePanelMap.get(project).getRoot(),"",true));
    }

    public static TranslatePanel getTranslatePanel(Project var0){
        System.out.println("get time"+new Date());
        return translatePanelMap.get(var0);
    }
    public static boolean showToolWindow(Project var0) {
        ToolWindow var1;
        if ((var1 = ToolWindowManager.getInstance(var0).getToolWindow("Translate")) != null) {
            var1.show((Runnable)null);
            return true;
        } else {
            return false;
        }
    }

    public static boolean showToolWindowContent(Project var0, String panelName) {
        ToolWindow var2;
        Content var3;
        if ((var2 = ToolWindowManager.getInstance(var0).getToolWindow("Translate")) != null && (var3 = var2.getContentManager().findContent(panelName)) != null) {
            var2.getContentManager().setSelectedContent(var3, true, true);
            return true;
        } else {
            return false;
        }
    }
}
